from django.db import models


# Create your models here.
class Publisher(models.Model):
    name = models.CharField(max_length=32)


class Book(models.Model):
    name = models.CharField(max_length=32)
    publisher = models.ForeignKey('Publisher', on_delete=models.CASCADE)  # 级联删除
    """
    on_delete:
        modles.CASCADE  #级联删除
        models.PROTECT  #保护
        models.SET(v)  # 删除后设置为某个值
        models.SET_DEFAULT, default=1  # 删除后设置为默认值：1
        models.SET_NULL  # 删除后设置为Null
        models.DO_NOTHING  # 没有任何影响
    """


class Author(models.Model):
    name = models.CharField(max_length=32)
    books = models.ManyToManyField('Book')  # 在Author表中创建多对多关系表
